package com.coldworks.base;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;

import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.common.SocializeConfig;
import com.umeng.socialize.controller.SocializeController;

import com.coldworks.base.manager.BaseConfManager;
import com.coldworks.base.manager.BasePrefManager;
import com.coldworks.base.manager.BaseSplashManager;
import com.coldworks.base.util.BaseCONST;

import com.coldworks.coldjoke.MainActivity;
import com.coldworks.coldjoke.manager.UserManager;

//@SuppressLint("HandlerLeak")
public class BaseSplashActivity extends BaseActivity {
	private View view;
	private boolean versionFirst;
	private int versionCode;

	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			if (versionFirst) {
				startActivity(new Intent(BaseSplashActivity.this,
						BaseGuideActivity.class));
				BasePrefManager.getInstance().setIntToPrefs(context,
						BaseCONST.KEY.VERSION_CODE, versionCode);
				finish();
			} else {
				startActivity(new Intent(BaseSplashActivity.this,
						MainActivity.class));
				finish();
			}

		}

	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MobclickAgent.onError(this);

		com.umeng.socom.Log.LOG = true;
		SocializeConfig config = new SocializeConfig();
		config.setDefaultShareLocation(false);
		SocializeController.setGlobalConfig(config);

		// 初始化用户数据,并自动登录
		UserManager.getInstance().initData(context);
		log.info("autologin: " + UserManager.getInstance().getIsAutoLogin());
		// if (UserManager.getInstance().getIsAutoLogin()) {
		// LoginManager.getInstance().loginTask(context,
		// UrlUtil.getLoginUrlFromLocal(), null, true);
		// }
		versionCode = BaseConfManager.getInstance().getVersionCode(context); // 版本号
		versionFirst = false;
		// versionFirst = versionCode > BasePrefManager.getInstance()
		// .getIntFromPrefs(ctx, BaseCONST.KEY.VERSION_CODE, 0) ? true
		// : false;
		view = BaseSplashManager.getInstance().show(context, versionFirst,
				handler);
		setContentView(view);
	}
}
